package com.ys.controller.api.finance;

import com.ys.config.MenuId;
import com.ys.entity.finance.TcwWanliCurrencyExchange;
import com.ys.entity.finance.TcwWanliTransfer;
import com.ys.entity.sys.YsCol;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.UploadService;
import com.ys.util.ExportExcelUtils;
import com.ys.util.admin.ConditionUtil;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 预付款退回付款操作记录
 */
@Controller
@RequestMapping("/api/inter/tcwWanliTransfer")
public class ApiInterTcwWanliTransferController {


    @Autowired
    private CommonApiService<TcwWanliTransfer> commonApiService;


    @RequiresPermissions("tcwWanliTransfer:view")
    @RequestMapping("/search")
    @ResponseBody
   public LayuiTableVoJA search(@ModelAttribute TcwWanliTransfer cond, String conditions){
        cond.setOrderby("A.id DESC");
        return commonApiService.searchLay(cond);
    }


    /**
     * 导出
     */
    @RequiresPermissions("tcwWanliTransfer:export")
    @RequestMapping("/export")
    @ResponseBody
    public R export(@ModelAttribute TcwWanliTransfer cond, String conditions){
        try {
            cond.setPage(0).setSize(999999);
            //获取菜单字段数据
            List<YsCol> listField = new YsCol()
                    .setMenuId(MenuId.Tcw_WanliTransfer)
                    .setFrontShow(1)
                    .setOrderby("A.SortNo asc")
                    .queryList();
            //获取数据
            List<Map<String, Object>> listData = cond.queryMap();
            //处理数据
            ExportExcelUtils<TcwWanliTransfer> util = new ExportExcelUtils<>(new TcwWanliTransfer());
            String toFilePath = util.exportExcel(listData, listField, "万里汇API付款操作记录表");
            UploadService.UploadDto dto = commonApiService.uploadLocalToServer(toFilePath);
            return R.ok(dto.getUrl());
        }catch (Exception e){
            return R.error("导出失败，请稍后重试！");
        }
    }

}
